import request from '../../utils/wxRequest';
import { GET_IP_ADDRESS } from '../mutation-types';

const state = {
  address: ''
};

const getters = {
  ip: (state) => state.address
};

const mutations = {
  [GET_IP_ADDRESS](state, payload) {
    state.address = payload.data;
  }
};

const actions = {
  [GET_IP_ADDRESS]({ commit }) {
    return request.get('https://yzl1030.com/test/ip')
      .then((res) => {
        console.log('resolve --->', res);
        commit({
          type: GET_IP_ADDRESS,
          data: res.data
        });
      })
      .catch((err) => {
        console.log('error --->', err);
      });
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
